package com.huike.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huike.pojo.ChargeHospital;
import com.huike.service.ChargeHospitalService;
import com.huike.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.rmi.CORBA.Stub;
import java.util.List;
@Controller
@RequestMapping("Hospital")
@ResponseBody
public class ChargeHospitalContorller {
    @Autowired
    private ChargeHospitalService chargeHospitalService;

    @RequestMapping("list3")
    public ResultVO<PageInfo> getChargeHospitalAll(String id, String registerName,  @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5")  Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<ChargeHospital> ch = chargeHospitalService.getgetChargeHospitalAll(registerName,id);
        PageInfo pageInfo = new PageInfo(ch,5);
        return new ResultVO(pageInfo);
    }

    @RequestMapping("add")
    public ResultVO addChargeHospital(ChargeHospital chargeHospital){
        try{
            chargeHospitalService.addChargeHospital(chargeHospital);
            return new ResultVO(200,"添加成功");
        }catch (Exception e){
            System.out.println(e);
            return new ResultVO(300,"添加失败");
        }

    }

    @RequestMapping("getCharge")
    public ResultVO getChargeHospitalById(Integer id){
        ChargeHospital chargeHospital = chargeHospitalService.getChargeHospitalById(id);
        return new ResultVO(chargeHospital);
    }
    @RequestMapping("getChargeadd")
    public ResultVO getChargeHospitaladd(Integer id){
        ChargeHospital chargeHospital=chargeHospitalService.getChargeHospitaladd(id);
        System.out.println(chargeHospital);
        return new ResultVO(chargeHospital);
    }
    @RequestMapping("queryByName")
    public ResultVO getChargeHospitaladl(String chargeName){
        ChargeHospital chargeHospital=chargeHospitalService.getChargeHospitaladl(chargeName);
        return new ResultVO(chargeHospital);
    }
}
